{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "abstract-employer",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "sns.set()\n",
    "\n",
    "DATA_PATH = r'./data/'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "informative-competition",
   "metadata": {},
   "source": [
    "### 一、总览：数据探索：\n",
    "#### 1.EDA价值主要在于熟悉了解整个数据集的基本情况（缺失值，异常值），对数据集进行验证是否可以进行接下来的机器学习或者深度学习建模.\n",
    "\n",
    "#### 2.了解变量间的相互关系、变量与预测值之间的存在关系。\n",
    "\n",
    "#### 3.为特征工程做准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "traditional-yield",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(DATA_PATH + \"train.csv\", sep=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "retained-arcade",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据维度为： (800000, 47)\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 800000 entries, 0 to 799999\n",
      "Data columns (total 47 columns):\n",
      " #   Column              Non-Null Count   Dtype  \n",
      "---  ------              --------------   -----  \n",
      " 0   id                  800000 non-null  int64  \n",
      " 1   loanAmnt            800000 non-null  float64\n",
      " 2   term                800000 non-null  int64  \n",
      " 3   interestRate        800000 non-null  float64\n",
      " 4   installment         800000 non-null  float64\n",
      " 5   grade               800000 non-null  object \n",
      " 6   subGrade            800000 non-null  object \n",
      " 7   employmentTitle     799999 non-null  float64\n",
      " 8   employmentLength    753201 non-null  object \n",
      " 9   homeOwnership       800000 non-null  int64  \n",
      " 10  annualIncome        800000 non-null  float64\n",
      " 11  verificationStatus  800000 non-null  int64  \n",
      " 12  issueDate           800000 non-null  object \n",
      " 13  isDefault           800000 non-null  int64  \n",
      " 14  purpose             800000 non-null  int64  \n",
      " 15  postCode            799999 non-null  float64\n",
      " 16  regionCode          800000 non-null  int64  \n",
      " 17  dti                 799761 non-null  float64\n",
      " 18  delinquency_2years  800000 non-null  float64\n",
      " 19  ficoRangeLow        800000 non-null  float64\n",
      " 20  ficoRangeHigh       800000 non-null  float64\n",
      " 21  openAcc             800000 non-null  float64\n",
      " 22  pubRec              800000 non-null  float64\n",
      " 23  pubRecBankruptcies  799595 non-null  float64\n",
      " 24  revolBal            800000 non-null  float64\n",
      " 25  revolUtil           799469 non-null  float64\n",
      " 26  totalAcc            800000 non-null  float64\n",
      " 27  initialListStatus   800000 non-null  int64  \n",
      " 28  applicationType     800000 non-null  int64  \n",
      " 29  earliesCreditLine   800000 non-null  object \n",
      " 30  title               799999 non-null  float64\n",
      " 31  policyCode          800000 non-null  float64\n",
      " 32  n0                  759730 non-null  float64\n",
      " 33  n1                  759730 non-null  float64\n",
      " 34  n2                  759730 non-null  float64\n",
      " 35  n3                  759730 non-null  float64\n",
      " 36  n4                  766761 non-null  float64\n",
      " 37  n5                  759730 non-null  float64\n",
      " 38  n6                  759730 non-null  float64\n",
      " 39  n7                  759730 non-null  float64\n",
      " 40  n8                  759729 non-null  float64\n",
      " 41  n9                  759730 non-null  float64\n",
      " 42  n10                 766761 non-null  float64\n",
      " 43  n11                 730248 non-null  float64\n",
      " 44  n12                 759730 non-null  float64\n",
      " 45  n13                 759730 non-null  float64\n",
      " 46  n14                 759730 non-null  float64\n",
      "dtypes: float64(33), int64(9), object(5)\n",
      "memory usage: 286.9+ MB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(\"数据维度为：\", data.shape)\n",
    "print(data.info())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "greek-nudist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>loanAmnt</th>\n",
       "      <th>term</th>\n",
       "      <th>interestRate</th>\n",
       "      <th>installment</th>\n",
       "      <th>employmentTitle</th>\n",
       "      <th>homeOwnership</th>\n",
       "      <th>annualIncome</th>\n",
       "      <th>verificationStatus</th>\n",
       "      <th>isDefault</th>\n",
       "      <th>...</th>\n",
       "      <th>n5</th>\n",
       "      <th>n6</th>\n",
       "      <th>n7</th>\n",
       "      <th>n8</th>\n",
       "      <th>n9</th>\n",
       "      <th>n10</th>\n",
       "      <th>n11</th>\n",
       "      <th>n12</th>\n",
       "      <th>n13</th>\n",
       "      <th>n14</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>799999.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>8.000000e+05</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>759729.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>766761.000000</td>\n",
       "      <td>730248.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "      <td>759730.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>399999.500000</td>\n",
       "      <td>14416.818875</td>\n",
       "      <td>3.482745</td>\n",
       "      <td>13.238391</td>\n",
       "      <td>437.947723</td>\n",
       "      <td>72005.351714</td>\n",
       "      <td>0.614213</td>\n",
       "      <td>7.613391e+04</td>\n",
       "      <td>1.009683</td>\n",
       "      <td>0.199513</td>\n",
       "      <td>...</td>\n",
       "      <td>8.107937</td>\n",
       "      <td>8.575994</td>\n",
       "      <td>8.282953</td>\n",
       "      <td>14.622488</td>\n",
       "      <td>5.592345</td>\n",
       "      <td>11.643896</td>\n",
       "      <td>0.000815</td>\n",
       "      <td>0.003384</td>\n",
       "      <td>0.089366</td>\n",
       "      <td>2.178606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>230940.252013</td>\n",
       "      <td>8716.086178</td>\n",
       "      <td>0.855832</td>\n",
       "      <td>4.765757</td>\n",
       "      <td>261.460393</td>\n",
       "      <td>106585.640204</td>\n",
       "      <td>0.675749</td>\n",
       "      <td>6.894751e+04</td>\n",
       "      <td>0.782716</td>\n",
       "      <td>0.399634</td>\n",
       "      <td>...</td>\n",
       "      <td>4.799210</td>\n",
       "      <td>7.400536</td>\n",
       "      <td>4.561689</td>\n",
       "      <td>8.124610</td>\n",
       "      <td>3.216184</td>\n",
       "      <td>5.484104</td>\n",
       "      <td>0.030075</td>\n",
       "      <td>0.062041</td>\n",
       "      <td>0.509069</td>\n",
       "      <td>1.844377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>5.310000</td>\n",
       "      <td>15.690000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>199999.750000</td>\n",
       "      <td>8000.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>9.750000</td>\n",
       "      <td>248.450000</td>\n",
       "      <td>427.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>4.560000e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>399999.500000</td>\n",
       "      <td>12000.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>12.740000</td>\n",
       "      <td>375.135000</td>\n",
       "      <td>7755.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>6.500000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>599999.250000</td>\n",
       "      <td>20000.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.990000</td>\n",
       "      <td>580.710000</td>\n",
       "      <td>117663.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>9.000000e+04</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>799999.000000</td>\n",
       "      <td>40000.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>30.990000</td>\n",
       "      <td>1715.420000</td>\n",
       "      <td>378351.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>1.099920e+07</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>70.000000</td>\n",
       "      <td>132.000000</td>\n",
       "      <td>79.000000</td>\n",
       "      <td>128.000000</td>\n",
       "      <td>45.000000</td>\n",
       "      <td>82.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>39.000000</td>\n",
       "      <td>30.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 42 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  id       loanAmnt           term   interestRate  \\\n",
       "count  800000.000000  800000.000000  800000.000000  800000.000000   \n",
       "mean   399999.500000   14416.818875       3.482745      13.238391   \n",
       "std    230940.252013    8716.086178       0.855832       4.765757   \n",
       "min         0.000000     500.000000       3.000000       5.310000   \n",
       "25%    199999.750000    8000.000000       3.000000       9.750000   \n",
       "50%    399999.500000   12000.000000       3.000000      12.740000   \n",
       "75%    599999.250000   20000.000000       3.000000      15.990000   \n",
       "max    799999.000000   40000.000000       5.000000      30.990000   \n",
       "\n",
       "         installment  employmentTitle  homeOwnership  annualIncome  \\\n",
       "count  800000.000000    799999.000000  800000.000000  8.000000e+05   \n",
       "mean      437.947723     72005.351714       0.614213  7.613391e+04   \n",
       "std       261.460393    106585.640204       0.675749  6.894751e+04   \n",
       "min        15.690000         0.000000       0.000000  0.000000e+00   \n",
       "25%       248.450000       427.000000       0.000000  4.560000e+04   \n",
       "50%       375.135000      7755.000000       1.000000  6.500000e+04   \n",
       "75%       580.710000    117663.500000       1.000000  9.000000e+04   \n",
       "max      1715.420000    378351.000000       5.000000  1.099920e+07   \n",
       "\n",
       "       verificationStatus      isDefault  ...             n5             n6  \\\n",
       "count       800000.000000  800000.000000  ...  759730.000000  759730.000000   \n",
       "mean             1.009683       0.199513  ...       8.107937       8.575994   \n",
       "std              0.782716       0.399634  ...       4.799210       7.400536   \n",
       "min              0.000000       0.000000  ...       0.000000       0.000000   \n",
       "25%              0.000000       0.000000  ...       5.000000       4.000000   \n",
       "50%              1.000000       0.000000  ...       7.000000       7.000000   \n",
       "75%              2.000000       0.000000  ...      11.000000      11.000000   \n",
       "max              2.000000       1.000000  ...      70.000000     132.000000   \n",
       "\n",
       "                  n7             n8             n9            n10  \\\n",
       "count  759730.000000  759729.000000  759730.000000  766761.000000   \n",
       "mean        8.282953      14.622488       5.592345      11.643896   \n",
       "std         4.561689       8.124610       3.216184       5.484104   \n",
       "min         0.000000       1.000000       0.000000       0.000000   \n",
       "25%         5.000000       9.000000       3.000000       8.000000   \n",
       "50%         7.000000      13.000000       5.000000      11.000000   \n",
       "75%        10.000000      19.000000       7.000000      14.000000   \n",
       "max        79.000000     128.000000      45.000000      82.000000   \n",
       "\n",
       "                 n11            n12            n13            n14  \n",
       "count  730248.000000  759730.000000  759730.000000  759730.000000  \n",
       "mean        0.000815       0.003384       0.089366       2.178606  \n",
       "std         0.030075       0.062041       0.509069       1.844377  \n",
       "min         0.000000       0.000000       0.000000       0.000000  \n",
       "25%         0.000000       0.000000       0.000000       1.000000  \n",
       "50%         0.000000       0.000000       0.000000       2.000000  \n",
       "75%         0.000000       0.000000       0.000000       3.000000  \n",
       "max         4.000000       4.000000      39.000000      30.000000  \n",
       "\n",
       "[8 rows x 42 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adult-world",
   "metadata": {},
   "source": [
    "### 二、查看各个变量与违约情况的相关性"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "sonic-funeral",
   "metadata": {},
   "source": [
    "#### 1、违约基本分布\n",
    "#### 违约贷款占比 19.95%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "annual-extreme",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实用函数\n",
    "def view_default_relation(data, target_col):\n",
    "    pv_grade = pd.pivot_table(data, columns=['isDefault'], index=[target_col], values=['id'], aggfunc=[len]).reset_index()\n",
    "    pv_grade['total'] = pv_grade[(  'len', 'id',  0)] + pv_grade[(  'len', 'id',  1)]\n",
    "    pv_grade['non_default_share'] = pv_grade[(  'len', 'id',  0)] / pv_grade['total']\n",
    "    pv_grade['default_share'] = pv_grade[(  'len', 'id',  1)] / pv_grade['total']\n",
    "    return pv_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "dominant-entrepreneur",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>isDefault</th>\n",
       "      <th>share</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>640390</td>\n",
       "      <td>0.800488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>159610</td>\n",
       "      <td>0.199513</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index  isDefault     share\n",
       "0      0     640390  0.800488\n",
       "1      1     159610  0.199513"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "default_cnt = data['isDefault'].value_counts().reset_index()\n",
    "default_cnt['share'] = default_cnt['isDefault'] / data.shape[0]\n",
    "default_cnt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "economic-algeria",
   "metadata": {},
   "source": [
    "#### 2、贷款金额\n",
    "#### 贷款金额越高，违约的比例越高"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "allied-pacific",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>loan_amt_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2907</td>\n",
       "      <td>451</td>\n",
       "      <td>3358</td>\n",
       "      <td>0.865694</td>\n",
       "      <td>0.134306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>18159</td>\n",
       "      <td>2995</td>\n",
       "      <td>21154</td>\n",
       "      <td>0.858419</td>\n",
       "      <td>0.141581</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>70267</td>\n",
       "      <td>13608</td>\n",
       "      <td>83875</td>\n",
       "      <td>0.837759</td>\n",
       "      <td>0.162241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>183812</td>\n",
       "      <td>38246</td>\n",
       "      <td>222058</td>\n",
       "      <td>0.827766</td>\n",
       "      <td>0.172234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>133511</td>\n",
       "      <td>35055</td>\n",
       "      <td>168566</td>\n",
       "      <td>0.792040</td>\n",
       "      <td>0.207960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>98763</td>\n",
       "      <td>28852</td>\n",
       "      <td>127615</td>\n",
       "      <td>0.773914</td>\n",
       "      <td>0.226086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>96442</td>\n",
       "      <td>28585</td>\n",
       "      <td>125027</td>\n",
       "      <td>0.771369</td>\n",
       "      <td>0.228631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>36529</td>\n",
       "      <td>11818</td>\n",
       "      <td>48347</td>\n",
       "      <td>0.755559</td>\n",
       "      <td>0.244441</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          loan_amt_level     len          total non_default_share  \\\n",
       "                              id                                    \n",
       "isDefault                      0      1                             \n",
       "0                      0    2907    451    3358          0.865694   \n",
       "1                      1   18159   2995   21154          0.858419   \n",
       "2                      2   70267  13608   83875          0.837759   \n",
       "3                      3  183812  38246  222058          0.827766   \n",
       "4                      4  133511  35055  168566          0.792040   \n",
       "5                      5   98763  28852  127615          0.773914   \n",
       "6                      6   96442  28585  125027          0.771369   \n",
       "7                      7   36529  11818   48347          0.755559   \n",
       "\n",
       "          default_share  \n",
       "                         \n",
       "isDefault                \n",
       "0              0.134306  \n",
       "1              0.141581  \n",
       "2              0.162241  \n",
       "3              0.172234  \n",
       "4              0.207960  \n",
       "5              0.226086  \n",
       "6              0.228631  \n",
       "7              0.244441  "
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_amt_bins = [0,1000,2500,5000,10000,15000,20000,30000,40001]\n",
    "data['loan_amt_level'] = pd.cut(data['loanAmnt'], bins=load_amt_bins, labels=[i for i in range(len(load_amt_bins) - 1)])\n",
    "pv_load_amt = pd.pivot_table(data, columns=['isDefault'], index=['loan_amt_level'], values=['id'], aggfunc=[len]).reset_index()\n",
    "pv_load_amt['total'] = pv_load_amt[(  'len', 'id',  0)] + pv_load_amt[(  'len', 'id',  1)]\n",
    "pv_load_amt['non_default_share'] = pv_load_amt[(  'len', 'id',  0)] / pv_load_amt['total']\n",
    "pv_load_amt['default_share'] = pv_load_amt[(  'len', 'id',  1)] / pv_load_amt['total']\n",
    "pv_load_amt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "sustained-implementation",
   "metadata": {},
   "source": [
    "#### 3、贷款等级\n",
    "#### 可以看到贷款等级的排序还是符合预期的，等级越高，违约率越低"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "active-tuner",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>grade</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>131229</td>\n",
       "      <td>8432</td>\n",
       "      <td>139661</td>\n",
       "      <td>0.939625</td>\n",
       "      <td>0.060375</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>202611</td>\n",
       "      <td>31079</td>\n",
       "      <td>233690</td>\n",
       "      <td>0.867008</td>\n",
       "      <td>0.132992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>176012</td>\n",
       "      <td>51106</td>\n",
       "      <td>227118</td>\n",
       "      <td>0.774980</td>\n",
       "      <td>0.225020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>83157</td>\n",
       "      <td>36296</td>\n",
       "      <td>119453</td>\n",
       "      <td>0.696148</td>\n",
       "      <td>0.303852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E</td>\n",
       "      <td>34271</td>\n",
       "      <td>21390</td>\n",
       "      <td>55661</td>\n",
       "      <td>0.615709</td>\n",
       "      <td>0.384291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>F</td>\n",
       "      <td>10412</td>\n",
       "      <td>8641</td>\n",
       "      <td>19053</td>\n",
       "      <td>0.546476</td>\n",
       "      <td>0.453524</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>G</td>\n",
       "      <td>2698</td>\n",
       "      <td>2666</td>\n",
       "      <td>5364</td>\n",
       "      <td>0.502983</td>\n",
       "      <td>0.497017</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          grade     len          total non_default_share default_share\n",
       "                     id                                               \n",
       "isDefault             0      1                                        \n",
       "0             A  131229   8432  139661          0.939625      0.060375\n",
       "1             B  202611  31079  233690          0.867008      0.132992\n",
       "2             C  176012  51106  227118          0.774980      0.225020\n",
       "3             D   83157  36296  119453          0.696148      0.303852\n",
       "4             E   34271  21390   55661          0.615709      0.384291\n",
       "5             F   10412   8641   19053          0.546476      0.453524\n",
       "6             G    2698   2666    5364          0.502983      0.497017"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pv_grade = pd.pivot_table(data, columns=['isDefault'], index=['grade'], values=['id'], aggfunc=[len]).reset_index()\n",
    "pv_grade['total'] = pv_grade[(  'len', 'id',  0)] + pv_grade[(  'len', 'id',  1)]\n",
    "pv_grade['non_default_share'] = pv_grade[(  'len', 'id',  0)] / pv_grade['total']\n",
    "pv_grade['default_share'] = pv_grade[(  'len', 'id',  1)] / pv_grade['total']\n",
    "pv_grade"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "recognized-department",
   "metadata": {},
   "source": [
    "#### 4、贷款利率：利率越高，违约率越高\n",
    "#### 因为贷款利率和贷款等级紧密相关的，贷款等级低的借款人信用等级也低，贷款利率高\n",
    "#### 贷款利率和贷款等级强相关"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "celtic-university",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>interest_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>19026</td>\n",
       "      <td>674</td>\n",
       "      <td>19700</td>\n",
       "      <td>0.965787</td>\n",
       "      <td>0.034213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>97591</td>\n",
       "      <td>6504</td>\n",
       "      <td>104095</td>\n",
       "      <td>0.937519</td>\n",
       "      <td>0.062481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>88572</td>\n",
       "      <td>10922</td>\n",
       "      <td>99494</td>\n",
       "      <td>0.890225</td>\n",
       "      <td>0.109775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>108748</td>\n",
       "      <td>19309</td>\n",
       "      <td>128057</td>\n",
       "      <td>0.849216</td>\n",
       "      <td>0.150784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>59061</td>\n",
       "      <td>13393</td>\n",
       "      <td>72454</td>\n",
       "      <td>0.815152</td>\n",
       "      <td>0.184848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>100404</td>\n",
       "      <td>28562</td>\n",
       "      <td>128966</td>\n",
       "      <td>0.778531</td>\n",
       "      <td>0.221469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>90830</td>\n",
       "      <td>34536</td>\n",
       "      <td>125366</td>\n",
       "      <td>0.724519</td>\n",
       "      <td>0.275481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>38456</td>\n",
       "      <td>19686</td>\n",
       "      <td>58142</td>\n",
       "      <td>0.661415</td>\n",
       "      <td>0.338585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>29517</td>\n",
       "      <td>18596</td>\n",
       "      <td>48113</td>\n",
       "      <td>0.613493</td>\n",
       "      <td>0.386507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>8185</td>\n",
       "      <td>7428</td>\n",
       "      <td>15613</td>\n",
       "      <td>0.524243</td>\n",
       "      <td>0.475757</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          interest_level     len          total non_default_share  \\\n",
       "                              id                                    \n",
       "isDefault                      0      1                             \n",
       "0                      0   19026    674   19700          0.965787   \n",
       "1                      1   97591   6504  104095          0.937519   \n",
       "2                      2   88572  10922   99494          0.890225   \n",
       "3                      3  108748  19309  128057          0.849216   \n",
       "4                      4   59061  13393   72454          0.815152   \n",
       "5                      5  100404  28562  128966          0.778531   \n",
       "6                      6   90830  34536  125366          0.724519   \n",
       "7                      7   38456  19686   58142          0.661415   \n",
       "8                      8   29517  18596   48113          0.613493   \n",
       "9                      9    8185   7428   15613          0.524243   \n",
       "\n",
       "          default_share  \n",
       "                         \n",
       "isDefault                \n",
       "0              0.034213  \n",
       "1              0.062481  \n",
       "2              0.109775  \n",
       "3              0.150784  \n",
       "4              0.184848  \n",
       "5              0.221469  \n",
       "6              0.275481  \n",
       "7              0.338585  \n",
       "8              0.386507  \n",
       "9              0.475757  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interest_bins = np.array([0.05, 0.06,0.08,0.1,0.12,0.13,0.15,0.18,0.2,0.25,0.4]) * 100\n",
    "data['interest_level'] = pd.cut(data['interestRate'], bins=interest_bins, labels=[i for i in range(len(interest_bins) - 1)])\n",
    "pv_interest = view_default_relation(data, 'interest_level')\n",
    "pv_interest"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "weighted-burden",
   "metadata": {},
   "source": [
    "#### 5、收入\n",
    "#### 收入越高，违约率越低"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "dimensional-prescription",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    8.000000e+05\n",
       "mean     7.613391e+04\n",
       "std      6.894751e+04\n",
       "min      0.000000e+00\n",
       "25%      4.560000e+04\n",
       "50%      6.500000e+04\n",
       "75%      9.000000e+04\n",
       "max      1.099920e+07\n",
       "Name: annualIncome, dtype: float64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['annualIncome'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "pharmaceutical-whole",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>income_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>110</td>\n",
       "      <td>35</td>\n",
       "      <td>145</td>\n",
       "      <td>0.758621</td>\n",
       "      <td>0.241379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>625</td>\n",
       "      <td>223</td>\n",
       "      <td>848</td>\n",
       "      <td>0.737028</td>\n",
       "      <td>0.262972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>22316</td>\n",
       "      <td>7199</td>\n",
       "      <td>29515</td>\n",
       "      <td>0.756090</td>\n",
       "      <td>0.243910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>175781</td>\n",
       "      <td>51536</td>\n",
       "      <td>227317</td>\n",
       "      <td>0.773286</td>\n",
       "      <td>0.226714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>194591</td>\n",
       "      <td>50323</td>\n",
       "      <td>244914</td>\n",
       "      <td>0.794528</td>\n",
       "      <td>0.205472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>121648</td>\n",
       "      <td>26946</td>\n",
       "      <td>148594</td>\n",
       "      <td>0.818660</td>\n",
       "      <td>0.181340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>89170</td>\n",
       "      <td>17131</td>\n",
       "      <td>106301</td>\n",
       "      <td>0.838844</td>\n",
       "      <td>0.161156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>21808</td>\n",
       "      <td>3871</td>\n",
       "      <td>25679</td>\n",
       "      <td>0.849254</td>\n",
       "      <td>0.150746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>10200</td>\n",
       "      <td>1755</td>\n",
       "      <td>11955</td>\n",
       "      <td>0.853199</td>\n",
       "      <td>0.146801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>3074</td>\n",
       "      <td>427</td>\n",
       "      <td>3501</td>\n",
       "      <td>0.878035</td>\n",
       "      <td>0.121965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>884</td>\n",
       "      <td>118</td>\n",
       "      <td>1002</td>\n",
       "      <td>0.882236</td>\n",
       "      <td>0.117764</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          income_level     len          total non_default_share default_share\n",
       "                            id                                               \n",
       "isDefault                    0      1                                        \n",
       "0                    0     110     35     145          0.758621      0.241379\n",
       "1                    1     625    223     848          0.737028      0.262972\n",
       "2                    2   22316   7199   29515          0.756090      0.243910\n",
       "3                    3  175781  51536  227317          0.773286      0.226714\n",
       "4                    4  194591  50323  244914          0.794528      0.205472\n",
       "5                    5  121648  26946  148594          0.818660      0.181340\n",
       "6                    6   89170  17131  106301          0.838844      0.161156\n",
       "7                    7   21808   3871   25679          0.849254      0.150746\n",
       "8                    8   10200   1755   11955          0.853199      0.146801\n",
       "9                    9    3074    427    3501          0.878035      0.121965\n",
       "10                  10     884    118    1002          0.882236      0.117764"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "income_bins = np.array([0, 5000,10000,25000,50000,75000,100000,150000,200000,300000,500000,2e7]) \n",
    "data['income_level'] = pd.cut(data['annualIncome'], bins=income_bins, labels=[i for i in range(len(income_bins) - 1)])\n",
    "pv_income = view_default_relation(data, 'income_level')\n",
    "pv_income"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "printable-valentine",
   "metadata": {},
   "source": [
    "#### 6、债务收入比\n",
    "#### 这种U型关系，意味着有个比较合适的债务收入比\n",
    "#### 猜测：债务收入比低的人，一般是信用等级低难以获得贷款；债务收入比高的人则更可能还不起贷款"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "instructional-spell",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    799761.000000\n",
       "mean         18.284557\n",
       "std          11.150155\n",
       "min          -1.000000\n",
       "25%          11.790000\n",
       "50%          17.610000\n",
       "75%          24.060000\n",
       "max         999.000000\n",
       "Name: dti, dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['dti'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "intimate-gabriel",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>dti_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>411</td>\n",
       "      <td>107</td>\n",
       "      <td>518</td>\n",
       "      <td>0.793436</td>\n",
       "      <td>0.206564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2800</td>\n",
       "      <td>495</td>\n",
       "      <td>3295</td>\n",
       "      <td>0.849772</td>\n",
       "      <td>0.150228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>7754</td>\n",
       "      <td>1457</td>\n",
       "      <td>9211</td>\n",
       "      <td>0.841820</td>\n",
       "      <td>0.158180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>23383</td>\n",
       "      <td>3915</td>\n",
       "      <td>27298</td>\n",
       "      <td>0.856583</td>\n",
       "      <td>0.143417</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>38157</td>\n",
       "      <td>6510</td>\n",
       "      <td>44667</td>\n",
       "      <td>0.854255</td>\n",
       "      <td>0.145745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>51841</td>\n",
       "      <td>9346</td>\n",
       "      <td>61187</td>\n",
       "      <td>0.847255</td>\n",
       "      <td>0.152745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>135742</td>\n",
       "      <td>26984</td>\n",
       "      <td>162726</td>\n",
       "      <td>0.834175</td>\n",
       "      <td>0.165825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>139054</td>\n",
       "      <td>32770</td>\n",
       "      <td>171824</td>\n",
       "      <td>0.809282</td>\n",
       "      <td>0.190718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>186894</td>\n",
       "      <td>55693</td>\n",
       "      <td>242587</td>\n",
       "      <td>0.770421</td>\n",
       "      <td>0.229579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>52967</td>\n",
       "      <td>21779</td>\n",
       "      <td>74746</td>\n",
       "      <td>0.708627</td>\n",
       "      <td>0.291373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>769</td>\n",
       "      <td>320</td>\n",
       "      <td>1089</td>\n",
       "      <td>0.706152</td>\n",
       "      <td>0.293848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>427</td>\n",
       "      <td>186</td>\n",
       "      <td>613</td>\n",
       "      <td>0.696574</td>\n",
       "      <td>0.303426</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          dti_level     len          total non_default_share default_share\n",
       "                         id                                               \n",
       "isDefault                 0      1                                        \n",
       "0                 0     411    107     518          0.793436      0.206564\n",
       "1                 1    2800    495    3295          0.849772      0.150228\n",
       "2                 2    7754   1457    9211          0.841820      0.158180\n",
       "3                 3   23383   3915   27298          0.856583      0.143417\n",
       "4                 4   38157   6510   44667          0.854255      0.145745\n",
       "5                 5   51841   9346   61187          0.847255      0.152745\n",
       "6                 6  135742  26984  162726          0.834175      0.165825\n",
       "7                 7  139054  32770  171824          0.809282      0.190718\n",
       "8                 8  186894  55693  242587          0.770421      0.229579\n",
       "9                 9   52967  21779   74746          0.708627      0.291373\n",
       "10               10     769    320    1089          0.706152      0.293848\n",
       "11               11     427    186     613          0.696574      0.303426"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90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/zTRt4hIklPQi4gkuWQM+vlBF9CD9NkSVzJ/Pn22OJd0ffQiIvKXkvGKXkREOlDQi4gkuaQJejObY2abzGyLmd0ddD2xZGYFZvaSmVWYWbmZfTXommLNzFLNrMzMlgRdSyyZ2RAze8rMNkb+/c4OuqZYMrO/j/w3ud7MHjezjKBrOlFm9rCZ1ZnZ+g77hpnZ82a2OfLn0CBrPFFJEfRRLo6SyNqAr7v7FOCjwJeS7PNB8i5Ocx/wnLtPBqaTRJ/RzPIILzhU7O6nE54iZV6wVZ2UXwNzOu27G3jB3ScCL0S2E05SBD1RLI6SyNx9t7uvjrw+SDgsjmdNgLiWrIvTmFkWcB7wKwB3b3H3A4EWFXtpwAAzSwMyiX5m27jj7q8QXi2vo7nAo5HXjwLX9mZNsZIsQX+yi6MkDDMbC8wE3gy4lFj6OVEsTpOAxgP1wCORbqmHzGxg0EXFirtXEV4+dCewG2hw9+XBVhVzo9x9N4QvuICRAddzQpIl6E94cZREYmaDgN8BX0uWmUGPZ3GaBJQGzAJ+4e4zgcMk6K/+XYn0V88FxgFjgIFmpmnI41CyBP3JLI6SEMysH+GQf8zdFwRdTwwl8+I0lUClu7/329dThIM/WVwMbHf3endvBRYA5wRcU6zVmtlogMifdQHXc0KSJehPeHGURGBmRrift8Ld/z3oemIpmRencfcaYJeZTYrsmg1sCLCkWNsJfNTMMiP/jc4miQabIxYDn428/izwdIC1nLBuFx5JBMdaHCXgsmLpXOBm4G0zWxPZ9013XxpcSRKlLwOPRS5AtgG3BFxPzLj7m2b2FLCa8J1hZSTwlAFm9jhwATDCzCqB7wA/Ap40sy8Q/sH2yeAqPHGaAkFEJMklS9eNiIgcg4JeRCTJKehFRJKcgl5EJMkp6EVEkpyCXkQkySnoRUSS3P8HwxqqCwNwbIsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "dti_bins = np.array([-2, 0,1,2.5,5,7.5,10,15,20,30,50,75, 1000]) \n",
    "data['dti_level'] = pd.cut(data['dti'], bins=dti_bins, labels=[i for i in range(len(dti_bins) - 1)])\n",
    "pv_dti = view_default_relation(data, 'dti_level')\n",
    "pv_dti['default_share'].plot()\n",
    "pv_dti"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "differential-tomato",
   "metadata": {},
   "source": [
    "#### 7、债务收入比和收入等级的关系\n",
    "#### 暂时无结论\n",
    "#### 不过贷款最为活跃的群体应该是中低等收入白领"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "selective-refrigerator",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAQ/UlEQVR4nO3df2ydd3XH8c+Zk2huKTJVTEacZC6sClSNWJC1BDKhilClWytiVWJrRKaqG+QfNgpiQQmNVE1qlEpBqP1jQgppoVOqMFQiU42KEJUhNtRac2okA1m0UkoSJyQXFUOEvCVxz/7wzQ9f59a593nu97nnq/frn9jf3Pqco159+vT6ufeYuwsAEM8fVN0AAKA9BDgABEWAA0BQBDgABEWAA0BQi1IWW7p0qQ8ODqYsCQDhHT169Nfu3t94njTABwcHNTY2lrIkAIRnZr+83jkvoQBAUAQ4AARFgANAUAQ4AARFgANAUAvehWJmT0u6T9I5d7+zfnarpH+VNCjpdUl/5e6/6USDI+OT2nv4uE5PTWt5X6+2b1qt4bUDnSglSRrc8Z15Z68/fm8W9XKeLXW9nGdLXW/XyIQOjp7UjLt6zLRl3Uo9NrymI7VycyNX4F+XdE/D2Q5JL7r77ZJerH9fupHxSe08NKHJqWm5pMmpae08NKGR8clOlLvuk/atziPVy3m21PVyni11vV0jEzrw8gnN1D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Y2UEz+8OqeyrCzJ42s3Nm9pNrzm41syNm9j/1P99RZY/t6PoAT7E8uUKXJH3e3d8nab2kT2c022UPSzpWdRMd8qSk77r7eyW9X5nMaWYDkj4jacjd79Tsx0U/UG1XhX1d0j0NZzskvejut0t6sf59KF0f4EqwPLkq7n7G3V+pf31eswEwb69oVGa2QtK9kvZX3UvZzOztkj4s6SlJcvcL7j5VaVPlWiSp18wWSbpJJW/bSs3dfyipcaP2ZknP1L9+RtJwyp7KECHAb2h5cnRmNihpraTRilsp0xOSviDpzYr76IR3S6pJ+lr9JaL9ZnZz1U2Vwd0nJX1J0glJZyT91t2/V21XHbHM3c9IsxdTkt5ZcT8tixDgN7Q8OTIze5ukb0n6rLv/rup+ymBm90k65+5Hq+6lQxZJ+oCkr7j7Wkm/V8D/Bb+e+mvBmyXdJmm5pJvNbGu1XeF6IgR4x5cnV8nMFms2vJ9190NV91OiDZI+Zmava/Zlr4+Y2YFqWyrVKUmn3P3y/zE9p9lAz8FHJf3C3WvuflHSIUkfqrinTjhrZu+SpPqf5yrup2URArzjy5OrYmam2ddQj7n7l6vup0zuvtPdV7j7oGb/nX3f3bO5inP3X0k6aWar60cbJf2swpbKdELSejO7qf4c3ahMfkHb4HlJD9a/flDStyvspS2FdmKm4O6XzOzvJR3W1eXJP624rbJskPQ3kibM7Mf1sy/Wd42i+/2DpGfrFxavSXqo4n5K4e6jZvacpFc0e6fUuIK/7dzMDkq6S9JSMzsl6VFJj0v6ppn9nWb/o/Xx6jpsD2+lB4CgIryEAgC4DgIcAIIiwAEgKAIcAIIiwAEgKAIcAIIiwAEgqP8HNWVRnVAkN3wAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(data['dti_level'], data['income_level'])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "liberal-arrow",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"11\" halign=\"left\">len</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"11\" halign=\"left\">id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>income_level</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dti_level</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>168.0</td>\n",
       "      <td>109.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>56.0</td>\n",
       "      <td>639.0</td>\n",
       "      <td>746.0</td>\n",
       "      <td>687.0</td>\n",
       "      <td>623.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>141.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>107.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.0</td>\n",
       "      <td>366.0</td>\n",
       "      <td>2136.0</td>\n",
       "      <td>2434.0</td>\n",
       "      <td>1760.0</td>\n",
       "      <td>1392.0</td>\n",
       "      <td>460.0</td>\n",
       "      <td>277.0</td>\n",
       "      <td>178.0</td>\n",
       "      <td>203.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>31.0</td>\n",
       "      <td>936.0</td>\n",
       "      <td>6835.0</td>\n",
       "      <td>7178.0</td>\n",
       "      <td>4867.0</td>\n",
       "      <td>4265.0</td>\n",
       "      <td>1470.0</td>\n",
       "      <td>1017.0</td>\n",
       "      <td>486.0</td>\n",
       "      <td>213.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>1559.0</td>\n",
       "      <td>10464.0</td>\n",
       "      <td>11165.0</td>\n",
       "      <td>8352.0</td>\n",
       "      <td>8021.0</td>\n",
       "      <td>2645.0</td>\n",
       "      <td>1646.0</td>\n",
       "      <td>623.0</td>\n",
       "      <td>156.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>NaN</td>\n",
       "      <td>40.0</td>\n",
       "      <td>2077.0</td>\n",
       "      <td>13353.0</td>\n",
       "      <td>15936.0</td>\n",
       "      <td>12513.0</td>\n",
       "      <td>11091.0</td>\n",
       "      <td>3547.0</td>\n",
       "      <td>1895.0</td>\n",
       "      <td>607.0</td>\n",
       "      <td>128.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>4867.0</td>\n",
       "      <td>36573.0</td>\n",
       "      <td>48008.0</td>\n",
       "      <td>33968.0</td>\n",
       "      <td>27559.0</td>\n",
       "      <td>7196.0</td>\n",
       "      <td>3436.0</td>\n",
       "      <td>894.0</td>\n",
       "      <td>136.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>4952.0</td>\n",
       "      <td>45735.0</td>\n",
       "      <td>54806.0</td>\n",
       "      <td>34372.0</td>\n",
       "      <td>24115.0</td>\n",
       "      <td>5247.0</td>\n",
       "      <td>2032.0</td>\n",
       "      <td>402.0</td>\n",
       "      <td>38.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.0</td>\n",
       "      <td>221.0</td>\n",
       "      <td>9239.0</td>\n",
       "      <td>80280.0</td>\n",
       "      <td>80364.0</td>\n",
       "      <td>42058.0</td>\n",
       "      <td>24578.0</td>\n",
       "      <td>4252.0</td>\n",
       "      <td>1356.0</td>\n",
       "      <td>216.0</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>4758.0</td>\n",
       "      <td>30504.0</td>\n",
       "      <td>24028.0</td>\n",
       "      <td>9910.0</td>\n",
       "      <td>4605.0</td>\n",
       "      <td>627.0</td>\n",
       "      <td>153.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>5.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>347.0</td>\n",
       "      <td>531.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>100.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>283.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                len                                                     \\\n",
       "                 id                                                      \n",
       "income_level      0      1       2        3        4        5        6   \n",
       "dti_level                                                                \n",
       "0               2.0   11.0    75.0    168.0    109.0     82.0     51.0   \n",
       "1               NaN    NaN    56.0    639.0    746.0    687.0    623.0   \n",
       "2               NaN    5.0   366.0   2136.0   2434.0   1760.0   1392.0   \n",
       "3               NaN   31.0   936.0   6835.0   7178.0   4867.0   4265.0   \n",
       "4               3.0   33.0  1559.0  10464.0  11165.0   8352.0   8021.0   \n",
       "5               NaN   40.0  2077.0  13353.0  15936.0  12513.0  11091.0   \n",
       "6               2.0   87.0  4867.0  36573.0  48008.0  33968.0  27559.0   \n",
       "7               8.0  117.0  4952.0  45735.0  54806.0  34372.0  24115.0   \n",
       "8               5.0  221.0  9239.0  80280.0  80364.0  42058.0  24578.0   \n",
       "9              10.0  132.0  4758.0  30504.0  24028.0   9910.0   4605.0   \n",
       "10              5.0   45.0   347.0    531.0    135.0     25.0      1.0   \n",
       "11            100.0  126.0   283.0     99.0      5.0      NaN      NaN   \n",
       "\n",
       "                                            \n",
       "                                            \n",
       "income_level       7       8      9     10  \n",
       "dti_level                                   \n",
       "0               15.0     2.0    2.0    1.0  \n",
       "1              220.0   141.0   76.0  107.0  \n",
       "2              460.0   277.0  178.0  203.0  \n",
       "3             1470.0  1017.0  486.0  213.0  \n",
       "4             2645.0  1646.0  623.0  156.0  \n",
       "5             3547.0  1895.0  607.0  128.0  \n",
       "6             7196.0  3436.0  894.0  136.0  \n",
       "7             5247.0  2032.0  402.0   38.0  \n",
       "8             4252.0  1356.0  216.0   18.0  \n",
       "9              627.0   153.0   17.0    2.0  \n",
       "10               NaN     NaN    NaN    NaN  \n",
       "11               NaN     NaN    NaN    NaN  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.groupby('dti_level')['income_level'].count()\n",
    "pv_dti_income = pd.pivot_table(data, columns=['income_level'], index=['dti_level'], values=['id'], aggfunc=[len])\n",
    "pv_dti_income"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "athletic-effects",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAD+CAYAAADF/ZVnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAknklEQVR4nO3df3BTVf438HeSWqDIbZtiSmhRqPsgQVcZ4ZHZVUGLUMdvWqjsbDUL0x1UdLEVQRYKSItQ1LDuIm5BWH9N93mQx5lVkUZni7vFrw/sLjAqrJj6g9BCqWlDf5m2/ChNzvNH1zxim/SmuTekt++Xc2eae+499ySST04+9+QcnRBCgIiINEF/pRtARETKYVAnItIQBnUiIg1hUCci0hAGdSIiDWFQJyLSEAZ1IqIw7N+/H/PmzcPcuXORnZ2Nffv2AQBqamqQl5eHrKws5OXloba2NnCOGmVBCSIiksXv94tp06aJr776SgghRHV1tZgyZYrw+Xxi4cKFYs+ePUIIIfbs2SM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xYwZMxSve+/evXjllVcCN3ufeOIJ3HPPPYrVv3btWnz66ae4dOkSbr/9dqxZsyYwxHSggr2/1H5fU4+YDOpERDQwMZd+ISKigWNQJyLSEAZ1IiINYVAnItIQBnUiIg1hUCci0hAGdSIiDWFQJyLSkP8HL4lXGnfTYR8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.heatmap(pv_dti_income.values)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "premier-respect",
   "metadata": {},
   "source": [
    "#### 8、贷款名称\n",
    "#### 贷款类型的违约率有高低之分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "activated-violation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39644"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['title'].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "legal-apparel",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>title_cnt</th>\n",
       "      <th>share</th>\n",
       "      <th>cumsum_share</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>393334</td>\n",
       "      <td>0.491667</td>\n",
       "      <td>0.491667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4.0</td>\n",
       "      <td>148211</td>\n",
       "      <td>0.185264</td>\n",
       "      <td>0.676931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.0</td>\n",
       "      <td>44748</td>\n",
       "      <td>0.055935</td>\n",
       "      <td>0.732866</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6.0</td>\n",
       "      <td>39742</td>\n",
       "      <td>0.049677</td>\n",
       "      <td>0.782544</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.0</td>\n",
       "      <td>14432</td>\n",
       "      <td>0.018040</td>\n",
       "      <td>0.800584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39639</th>\n",
       "      <td>60416.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>0.999994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39640</th>\n",
       "      <td>7960.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>0.999995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39641</th>\n",
       "      <td>52527.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>0.999996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39642</th>\n",
       "      <td>26420.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>0.999997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39643</th>\n",
       "      <td>1046.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>0.999999</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>39644 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         title  title_cnt     share  cumsum_share\n",
       "0          0.0     393334  0.491667      0.491667\n",
       "1          4.0     148211  0.185264      0.676931\n",
       "2          5.0      44748  0.055935      0.732866\n",
       "3          6.0      39742  0.049677      0.782544\n",
       "4          3.0      14432  0.018040      0.800584\n",
       "...        ...        ...       ...           ...\n",
       "39639  60416.0          1  0.000001      0.999994\n",
       "39640   7960.0          1  0.000001      0.999995\n",
       "39641  52527.0          1  0.000001      0.999996\n",
       "39642  26420.0          1  0.000001      0.999997\n",
       "39643   1046.0          1  0.000001      0.999999\n",
       "\n",
       "[39644 rows x 4 columns]"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title = data['title'].value_counts().reset_index().rename(columns={\"index\":\"title\", \"title\":\"title_cnt\"})\n",
    "\n",
    "title['share']  = title['title_cnt'] / data.shape[0]\n",
    "title['cumsum_share'] = title['share'].cumsum()\n",
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "lightweight-constraint",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>307596</td>\n",
       "      <td>85738</td>\n",
       "      <td>393334</td>\n",
       "      <td>0.782022</td>\n",
       "      <td>0.217978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>4868</td>\n",
       "      <td>2137</td>\n",
       "      <td>7005</td>\n",
       "      <td>0.694932</td>\n",
       "      <td>0.305068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>7018</td>\n",
       "      <td>2888</td>\n",
       "      <td>9906</td>\n",
       "      <td>0.708460</td>\n",
       "      <td>0.291540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>11477</td>\n",
       "      <td>2955</td>\n",
       "      <td>14432</td>\n",
       "      <td>0.795247</td>\n",
       "      <td>0.204753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "      <td>122231</td>\n",
       "      <td>25980</td>\n",
       "      <td>148211</td>\n",
       "      <td>0.824709</td>\n",
       "      <td>0.175291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>36618</td>\n",
       "      <td>8130</td>\n",
       "      <td>44748</td>\n",
       "      <td>0.818316</td>\n",
       "      <td>0.181684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "      <td>31205</td>\n",
       "      <td>8537</td>\n",
       "      <td>39742</td>\n",
       "      <td>0.785189</td>\n",
       "      <td>0.214811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>2685</td>\n",
       "      <td>860</td>\n",
       "      <td>3545</td>\n",
       "      <td>0.757405</td>\n",
       "      <td>0.242595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "      <td>3824</td>\n",
       "      <td>929</td>\n",
       "      <td>4753</td>\n",
       "      <td>0.804544</td>\n",
       "      <td>0.195456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>5663</td>\n",
       "      <td>1048</td>\n",
       "      <td>6711</td>\n",
       "      <td>0.843838</td>\n",
       "      <td>0.156162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>6251</td>\n",
       "      <td>1824</td>\n",
       "      <td>8075</td>\n",
       "      <td>0.774118</td>\n",
       "      <td>0.225882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11.0</td>\n",
       "      <td>3590</td>\n",
       "      <td>1141</td>\n",
       "      <td>4731</td>\n",
       "      <td>0.758825</td>\n",
       "      <td>0.241175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12.0</td>\n",
       "      <td>313</td>\n",
       "      <td>112</td>\n",
       "      <td>425</td>\n",
       "      <td>0.736471</td>\n",
       "      <td>0.263529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>26.0</td>\n",
       "      <td>1273</td>\n",
       "      <td>148</td>\n",
       "      <td>1421</td>\n",
       "      <td>0.895848</td>\n",
       "      <td>0.104152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>28.0</td>\n",
       "      <td>2646</td>\n",
       "      <td>420</td>\n",
       "      <td>3066</td>\n",
       "      <td>0.863014</td>\n",
       "      <td>0.136986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>38.0</td>\n",
       "      <td>8057</td>\n",
       "      <td>1360</td>\n",
       "      <td>9417</td>\n",
       "      <td>0.855580</td>\n",
       "      <td>0.144420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>41.0</td>\n",
       "      <td>332</td>\n",
       "      <td>68</td>\n",
       "      <td>400</td>\n",
       "      <td>0.830000</td>\n",
       "      <td>0.170000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>51.0</td>\n",
       "      <td>387</td>\n",
       "      <td>72</td>\n",
       "      <td>459</td>\n",
       "      <td>0.843137</td>\n",
       "      <td>0.156863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>56.0</td>\n",
       "      <td>580</td>\n",
       "      <td>117</td>\n",
       "      <td>697</td>\n",
       "      <td>0.832138</td>\n",
       "      <td>0.167862</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>63.0</td>\n",
       "      <td>330</td>\n",
       "      <td>93</td>\n",
       "      <td>423</td>\n",
       "      <td>0.780142</td>\n",
       "      <td>0.219858</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>65.0</td>\n",
       "      <td>251</td>\n",
       "      <td>53</td>\n",
       "      <td>304</td>\n",
       "      <td>0.825658</td>\n",
       "      <td>0.174342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>68.0</td>\n",
       "      <td>256</td>\n",
       "      <td>59</td>\n",
       "      <td>315</td>\n",
       "      <td>0.812698</td>\n",
       "      <td>0.187302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>70.0</td>\n",
       "      <td>2294</td>\n",
       "      <td>585</td>\n",
       "      <td>2879</td>\n",
       "      <td>0.796804</td>\n",
       "      <td>0.203196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>71.0</td>\n",
       "      <td>1063</td>\n",
       "      <td>182</td>\n",
       "      <td>1245</td>\n",
       "      <td>0.853815</td>\n",
       "      <td>0.146185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>76.0</td>\n",
       "      <td>366</td>\n",
       "      <td>75</td>\n",
       "      <td>441</td>\n",
       "      <td>0.829932</td>\n",
       "      <td>0.170068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>94.0</td>\n",
       "      <td>913</td>\n",
       "      <td>138</td>\n",
       "      <td>1051</td>\n",
       "      <td>0.868696</td>\n",
       "      <td>0.131304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>95.0</td>\n",
       "      <td>781</td>\n",
       "      <td>73</td>\n",
       "      <td>854</td>\n",
       "      <td>0.914520</td>\n",
       "      <td>0.085480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>104.0</td>\n",
       "      <td>335</td>\n",
       "      <td>46</td>\n",
       "      <td>381</td>\n",
       "      <td>0.879265</td>\n",
       "      <td>0.120735</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>106.0</td>\n",
       "      <td>1060</td>\n",
       "      <td>236</td>\n",
       "      <td>1296</td>\n",
       "      <td>0.817901</td>\n",
       "      <td>0.182099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>138.0</td>\n",
       "      <td>259</td>\n",
       "      <td>42</td>\n",
       "      <td>301</td>\n",
       "      <td>0.860465</td>\n",
       "      <td>0.139535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>148.0</td>\n",
       "      <td>508</td>\n",
       "      <td>91</td>\n",
       "      <td>599</td>\n",
       "      <td>0.848080</td>\n",
       "      <td>0.151920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>173.0</td>\n",
       "      <td>340</td>\n",
       "      <td>76</td>\n",
       "      <td>416</td>\n",
       "      <td>0.817308</td>\n",
       "      <td>0.182692</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>191.0</td>\n",
       "      <td>357</td>\n",
       "      <td>76</td>\n",
       "      <td>433</td>\n",
       "      <td>0.824480</td>\n",
       "      <td>0.175520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>193.0</td>\n",
       "      <td>1930</td>\n",
       "      <td>323</td>\n",
       "      <td>2253</td>\n",
       "      <td>0.856636</td>\n",
       "      <td>0.143364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>206.0</td>\n",
       "      <td>297</td>\n",
       "      <td>69</td>\n",
       "      <td>366</td>\n",
       "      <td>0.811475</td>\n",
       "      <td>0.188525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>234.0</td>\n",
       "      <td>796</td>\n",
       "      <td>80</td>\n",
       "      <td>876</td>\n",
       "      <td>0.908676</td>\n",
       "      <td>0.091324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>241.0</td>\n",
       "      <td>298</td>\n",
       "      <td>52</td>\n",
       "      <td>350</td>\n",
       "      <td>0.851429</td>\n",
       "      <td>0.148571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>259.0</td>\n",
       "      <td>285</td>\n",
       "      <td>52</td>\n",
       "      <td>337</td>\n",
       "      <td>0.845697</td>\n",
       "      <td>0.154303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>268.0</td>\n",
       "      <td>928</td>\n",
       "      <td>123</td>\n",
       "      <td>1051</td>\n",
       "      <td>0.882969</td>\n",
       "      <td>0.117031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>289.0</td>\n",
       "      <td>325</td>\n",
       "      <td>39</td>\n",
       "      <td>364</td>\n",
       "      <td>0.892857</td>\n",
       "      <td>0.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>299.0</td>\n",
       "      <td>600</td>\n",
       "      <td>115</td>\n",
       "      <td>715</td>\n",
       "      <td>0.839161</td>\n",
       "      <td>0.160839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>413.0</td>\n",
       "      <td>306</td>\n",
       "      <td>36</td>\n",
       "      <td>342</td>\n",
       "      <td>0.894737</td>\n",
       "      <td>0.105263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>454.0</td>\n",
       "      <td>394</td>\n",
       "      <td>56</td>\n",
       "      <td>450</td>\n",
       "      <td>0.875556</td>\n",
       "      <td>0.124444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>544.0</td>\n",
       "      <td>281</td>\n",
       "      <td>63</td>\n",
       "      <td>344</td>\n",
       "      <td>0.816860</td>\n",
       "      <td>0.183140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>664.0</td>\n",
       "      <td>311</td>\n",
       "      <td>76</td>\n",
       "      <td>387</td>\n",
       "      <td>0.803618</td>\n",
       "      <td>0.196382</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           title     len          total non_default_share default_share\n",
       "                      id                                               \n",
       "isDefault              0      1                                        \n",
       "0            0.0  307596  85738  393334          0.782022      0.217978\n",
       "1            1.0    4868   2137    7005          0.694932      0.305068\n",
       "2            2.0    7018   2888    9906          0.708460      0.291540\n",
       "3            3.0   11477   2955   14432          0.795247      0.204753\n",
       "4            4.0  122231  25980  148211          0.824709      0.175291\n",
       "5            5.0   36618   8130   44748          0.818316      0.181684\n",
       "6            6.0   31205   8537   39742          0.785189      0.214811\n",
       "7            7.0    2685    860    3545          0.757405      0.242595\n",
       "8            8.0    3824    929    4753          0.804544      0.195456\n",
       "9            9.0    5663   1048    6711          0.843838      0.156162\n",
       "10          10.0    6251   1824    8075          0.774118      0.225882\n",
       "11          11.0    3590   1141    4731          0.758825      0.241175\n",
       "12          12.0     313    112     425          0.736471      0.263529\n",
       "13          26.0    1273    148    1421          0.895848      0.104152\n",
       "14          28.0    2646    420    3066          0.863014      0.136986\n",
       "15          38.0    8057   1360    9417          0.855580      0.144420\n",
       "16          41.0     332     68     400          0.830000      0.170000\n",
       "17          51.0     387     72     459          0.843137      0.156863\n",
       "18          56.0     580    117     697          0.832138      0.167862\n",
       "19          63.0     330     93     423          0.780142      0.219858\n",
       "20          65.0     251     53     304          0.825658      0.174342\n",
       "21          68.0     256     59     315          0.812698      0.187302\n",
       "22          70.0    2294    585    2879          0.796804      0.203196\n",
       "23          71.0    1063    182    1245          0.853815      0.146185\n",
       "24          76.0     366     75     441          0.829932      0.170068\n",
       "25          94.0     913    138    1051          0.868696      0.131304\n",
       "26          95.0     781     73     854          0.914520      0.085480\n",
       "27         104.0     335     46     381          0.879265      0.120735\n",
       "28         106.0    1060    236    1296          0.817901      0.182099\n",
       "29         138.0     259     42     301          0.860465      0.139535\n",
       "30         148.0     508     91     599          0.848080      0.151920\n",
       "31         173.0     340     76     416          0.817308      0.182692\n",
       "32         191.0     357     76     433          0.824480      0.175520\n",
       "33         193.0    1930    323    2253          0.856636      0.143364\n",
       "34         206.0     297     69     366          0.811475      0.188525\n",
       "35         234.0     796     80     876          0.908676      0.091324\n",
       "36         241.0     298     52     350          0.851429      0.148571\n",
       "37         259.0     285     52     337          0.845697      0.154303\n",
       "38         268.0     928    123    1051          0.882969      0.117031\n",
       "39         289.0     325     39     364          0.892857      0.107143\n",
       "40         299.0     600    115     715          0.839161      0.160839\n",
       "41         413.0     306     36     342          0.894737      0.105263\n",
       "42         454.0     394     56     450          0.875556      0.124444\n",
       "43         544.0     281     63     344          0.816860      0.183140\n",
       "44         664.0     311     76     387          0.803618      0.196382"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspect_titles = title['title'][title['cumsum_share'] <= 0.9].tolist()\n",
    "pv_title = view_default_relation(data[data['title'].isin(inspect_titles)], 'title')\n",
    "pv_title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "distinct-surge",
   "metadata": {},
   "source": [
    "#### 9、贷款期限\n",
    "#### 5年期违约率显著升高"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "legendary-sense",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    606902\n",
       "5    193098\n",
       "Name: term, dtype: int64"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['term'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "elementary-reach",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>term</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>509776</td>\n",
       "      <td>97126</td>\n",
       "      <td>606902</td>\n",
       "      <td>0.839964</td>\n",
       "      <td>0.160036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5</td>\n",
       "      <td>130614</td>\n",
       "      <td>62484</td>\n",
       "      <td>193098</td>\n",
       "      <td>0.676413</td>\n",
       "      <td>0.323587</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          term     len          total non_default_share default_share\n",
       "                    id                                               \n",
       "isDefault            0      1                                        \n",
       "0            3  509776  97126  606902          0.839964      0.160036\n",
       "1            5  130614  62484  193098          0.676413      0.323587"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pv_term = view_default_relation(data, 'term')\n",
    "pv_term"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "incorporated-baseline",
   "metadata": {},
   "source": [
    "#### 10、违约事件数\n",
    "#### 与违约正相关"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "earlier-wichita",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>delinquency_2years_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>519265</td>\n",
       "      <td>126450</td>\n",
       "      <td>645715</td>\n",
       "      <td>0.804171</td>\n",
       "      <td>0.195829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>81207</td>\n",
       "      <td>21379</td>\n",
       "      <td>102586</td>\n",
       "      <td>0.791599</td>\n",
       "      <td>0.208401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>31664</td>\n",
       "      <td>9199</td>\n",
       "      <td>40863</td>\n",
       "      <td>0.774882</td>\n",
       "      <td>0.225118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>5571</td>\n",
       "      <td>1741</td>\n",
       "      <td>7312</td>\n",
       "      <td>0.761898</td>\n",
       "      <td>0.238102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2364</td>\n",
       "      <td>733</td>\n",
       "      <td>3097</td>\n",
       "      <td>0.763319</td>\n",
       "      <td>0.236681</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>267</td>\n",
       "      <td>89</td>\n",
       "      <td>356</td>\n",
       "      <td>0.750000</td>\n",
       "      <td>0.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>40</td>\n",
       "      <td>16</td>\n",
       "      <td>56</td>\n",
       "      <td>0.714286</td>\n",
       "      <td>0.285714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "      <td>15</td>\n",
       "      <td>0.800000</td>\n",
       "      <td>0.200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          delinquency_2years_level     len           total non_default_share  \\\n",
       "                                        id                                     \n",
       "isDefault                                0       1                             \n",
       "0                                0  519265  126450  645715          0.804171   \n",
       "1                                1   81207   21379  102586          0.791599   \n",
       "2                                2   31664    9199   40863          0.774882   \n",
       "3                                3    5571    1741    7312          0.761898   \n",
       "4                                4    2364     733    3097          0.763319   \n",
       "5                                5     267      89     356          0.750000   \n",
       "6                                6      40      16      56          0.714286   \n",
       "7                                7      12       3      15          0.800000   \n",
       "\n",
       "          default_share  \n",
       "                         \n",
       "isDefault                \n",
       "0              0.195829  \n",
       "1              0.208401  \n",
       "2              0.225118  \n",
       "3              0.238102  \n",
       "4              0.236681  \n",
       "5              0.250000  \n",
       "6              0.285714  \n",
       "7              0.200000  "
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deli_bins = np.array([-1, 0,1,3,5,10,15,20,50]) \n",
    "data['delinquency_2years_level'] = pd.cut(data['delinquency_2years'], bins=deli_bins, labels=[i for i in range(len(deli_bins) - 1)])\n",
    "pv_delinquency = view_default_relation(data, 'delinquency_2years_level')\n",
    "pv_delinquency"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "noticed-public",
   "metadata": {},
   "source": [
    "#### 11、工作年限"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "traditional-director",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>employmentLength</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1 year</td>\n",
       "      <td>41719</td>\n",
       "      <td>10770</td>\n",
       "      <td>52489</td>\n",
       "      <td>0.794814</td>\n",
       "      <td>0.205186</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10+ years</td>\n",
       "      <td>213608</td>\n",
       "      <td>49145</td>\n",
       "      <td>262753</td>\n",
       "      <td>0.812961</td>\n",
       "      <td>0.187039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2 years</td>\n",
       "      <td>57884</td>\n",
       "      <td>14474</td>\n",
       "      <td>72358</td>\n",
       "      <td>0.799967</td>\n",
       "      <td>0.200033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3 years</td>\n",
       "      <td>51226</td>\n",
       "      <td>12926</td>\n",
       "      <td>64152</td>\n",
       "      <td>0.798510</td>\n",
       "      <td>0.201490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4 years</td>\n",
       "      <td>38470</td>\n",
       "      <td>9515</td>\n",
       "      <td>47985</td>\n",
       "      <td>0.801709</td>\n",
       "      <td>0.198291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5 years</td>\n",
       "      <td>40295</td>\n",
       "      <td>9807</td>\n",
       "      <td>50102</td>\n",
       "      <td>0.804259</td>\n",
       "      <td>0.195741</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6 years</td>\n",
       "      <td>30071</td>\n",
       "      <td>7183</td>\n",
       "      <td>37254</td>\n",
       "      <td>0.807188</td>\n",
       "      <td>0.192812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7 years</td>\n",
       "      <td>28501</td>\n",
       "      <td>6906</td>\n",
       "      <td>35407</td>\n",
       "      <td>0.804954</td>\n",
       "      <td>0.195046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8 years</td>\n",
       "      <td>29054</td>\n",
       "      <td>7138</td>\n",
       "      <td>36192</td>\n",
       "      <td>0.802774</td>\n",
       "      <td>0.197226</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9 years</td>\n",
       "      <td>24266</td>\n",
       "      <td>6006</td>\n",
       "      <td>30272</td>\n",
       "      <td>0.801599</td>\n",
       "      <td>0.198401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>&lt; 1 year</td>\n",
       "      <td>51076</td>\n",
       "      <td>13161</td>\n",
       "      <td>64237</td>\n",
       "      <td>0.795118</td>\n",
       "      <td>0.204882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          employmentLength     len          total non_default_share  \\\n",
       "                                id                                    \n",
       "isDefault                        0      1                             \n",
       "0                   1 year   41719  10770   52489          0.794814   \n",
       "1                10+ years  213608  49145  262753          0.812961   \n",
       "2                  2 years   57884  14474   72358          0.799967   \n",
       "3                  3 years   51226  12926   64152          0.798510   \n",
       "4                  4 years   38470   9515   47985          0.801709   \n",
       "5                  5 years   40295   9807   50102          0.804259   \n",
       "6                  6 years   30071   7183   37254          0.807188   \n",
       "7                  7 years   28501   6906   35407          0.804954   \n",
       "8                  8 years   29054   7138   36192          0.802774   \n",
       "9                  9 years   24266   6006   30272          0.801599   \n",
       "10                < 1 year   51076  13161   64237          0.795118   \n",
       "\n",
       "          default_share  \n",
       "                         \n",
       "isDefault                \n",
       "0              0.205186  \n",
       "1              0.187039  \n",
       "2              0.200033  \n",
       "3              0.201490  \n",
       "4              0.198291  \n",
       "5              0.195741  \n",
       "6              0.192812  \n",
       "7              0.195046  \n",
       "8              0.197226  \n",
       "9              0.198401  \n",
       "10             0.204882  "
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data['employmentLength'].value_counts()\n",
    "pv_employmentLength = view_default_relation(data, 'employmentLength')\n",
    "pv_employmentLength"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "asian-smile",
   "metadata": {},
   "source": [
    "#### 12、借款人在登记时提供的房屋所有权状况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "demonstrated-gnome",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>homeOwnership</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>327850</td>\n",
       "      <td>67882</td>\n",
       "      <td>395732</td>\n",
       "      <td>0.828465</td>\n",
       "      <td>0.171535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>243929</td>\n",
       "      <td>73731</td>\n",
       "      <td>317660</td>\n",
       "      <td>0.767893</td>\n",
       "      <td>0.232107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>68374</td>\n",
       "      <td>17935</td>\n",
       "      <td>86309</td>\n",
       "      <td>0.792200</td>\n",
       "      <td>0.207800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>147</td>\n",
       "      <td>38</td>\n",
       "      <td>185</td>\n",
       "      <td>0.794595</td>\n",
       "      <td>0.205405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>28</td>\n",
       "      <td>5</td>\n",
       "      <td>33</td>\n",
       "      <td>0.848485</td>\n",
       "      <td>0.151515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>62</td>\n",
       "      <td>19</td>\n",
       "      <td>81</td>\n",
       "      <td>0.765432</td>\n",
       "      <td>0.234568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          homeOwnership     len          total non_default_share default_share\n",
       "                             id                                               \n",
       "isDefault                     0      1                                        \n",
       "0                     0  327850  67882  395732          0.828465      0.171535\n",
       "1                     1  243929  73731  317660          0.767893      0.232107\n",
       "2                     2   68374  17935   86309          0.792200      0.207800\n",
       "3                     3     147     38     185          0.794595      0.205405\n",
       "4                     4      28      5      33          0.848485      0.151515\n",
       "5                     5      62     19      81          0.765432      0.234568"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pv_homeOwnership = view_default_relation(data, 'homeOwnership')\n",
    "pv_homeOwnership"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "medieval-liberty",
   "metadata": {},
   "source": [
    "#### 13、总额度\n",
    "#### 微弱的U型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "bearing-whale",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    800000.000000\n",
       "mean         24.998861\n",
       "std          11.999201\n",
       "min           2.000000\n",
       "25%          16.000000\n",
       "50%          23.000000\n",
       "75%          32.000000\n",
       "max         162.000000\n",
       "Name: totalAcc, dtype: float64"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['totalAcc'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "friendly-vatican",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>total_acc_level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">len</th>\n",
       "      <th>total</th>\n",
       "      <th>non_default_share</th>\n",
       "      <th>default_share</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isDefault</th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>691</td>\n",
       "      <td>278</td>\n",
       "      <td>969</td>\n",
       "      <td>0.713106</td>\n",
       "      <td>0.286894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>5919</td>\n",
       "      <td>1644</td>\n",
       "      <td>7563</td>\n",
       "      <td>0.782626</td>\n",
       "      <td>0.217374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>12686</td>\n",
       "      <td>3432</td>\n",
       "      <td>16118</td>\n",
       "      <td>0.787070</td>\n",
       "      <td>0.212930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>33469</td>\n",
       "      <td>8925</td>\n",
       "      <td>42394</td>\n",
       "      <td>0.789475</td>\n",
       "      <td>0.210525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>89275</td>\n",
       "      <td>23589</td>\n",
       "      <td>112864</td>\n",
       "      <td>0.790996</td>\n",
       "      <td>0.209004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>112476</td>\n",
       "      <td>28550</td>\n",
       "      <td>141026</td>\n",
       "      <td>0.797555</td>\n",
       "      <td>0.202445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>204710</td>\n",
       "      <td>49805</td>\n",
       "      <td>254515</td>\n",
       "      <td>0.804314</td>\n",
       "      <td>0.195686</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>159352</td>\n",
       "      <td>37947</td>\n",
       "      <td>197299</td>\n",
       "      <td>0.807668</td>\n",
       "      <td>0.192332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>21736</td>\n",
       "      <td>5417</td>\n",
       "      <td>27153</td>\n",
       "      <td>0.800501</td>\n",
       "      <td>0.199499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>76</td>\n",
       "      <td>23</td>\n",
       "      <td>99</td>\n",
       "      <td>0.767677</td>\n",
       "      <td>0.232323</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          total_acc_level     len          total non_default_share  \\\n",
       "                               id                                    \n",
       "isDefault                       0      1                             \n",
       "0                       0     691    278     969          0.713106   \n",
       "1                       1    5919   1644    7563          0.782626   \n",
       "2                       2   12686   3432   16118          0.787070   \n",
       "3                       3   33469   8925   42394          0.789475   \n",
       "4                       4   89275  23589  112864          0.790996   \n",
       "5                       5  112476  28550  141026          0.797555   \n",
       "6                       6  204710  49805  254515          0.804314   \n",
       "7                       7  159352  37947  197299          0.807668   \n",
       "8                       8   21736   5417   27153          0.800501   \n",
       "9                       9      76     23      99          0.767677   \n",
       "\n",
       "          default_share  \n",
       "                         \n",
       "isDefault                \n",
       "0              0.286894  \n",
       "1              0.217374  \n",
       "2              0.212930  \n",
       "3              0.210525  \n",
       "4              0.209004  \n",
       "5              0.202445  \n",
       "6              0.195686  \n",
       "7              0.192332  \n",
       "8              0.199499  \n",
       "9              0.232323  "
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_acc_bins = np.array([0, 3,5,7,10,15,20,30,50,100,200]) \n",
    "data['total_acc_level'] = pd.cut(data['totalAcc'], bins=total_acc_bins, labels=[i for i in range(len(total_acc_bins) - 1)])\n",
    "pv_total_acc = view_default_relation(data, 'total_acc_level')\n",
    "pv_total_acc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "fluid-kansas",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_pickle('./processed_data/data_add.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "nonprofit-giving",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "welcome-newman",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "signal-startup",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
